/**
 * Created by dell on 2017/2/22.
 */
$(function () {
  	var bdbIpManage = {
		/* 初始数据 */
		defData: {
			pageSize: 20,
			ipType: {},
		    serverGroupId: '',
		    listSize: 3
		},

		/* 页面状态 */
		pageState: {
			search: '',
			page: 1,
		    modifiedId: '',
		    batchIds: '',
		  	oldData: {},
		    ipPageType: 'isUsed',
			serverGroupIdSel: '',
		  	ipTypeSel:'',
		    submitFlag: 0  //提交状态
		},

	  	/* 重置提交后请求 */
	  	resetPageState: function() {
		  	this.pageState = {
				search: '',
				page: 1,
				modifiedId: '',
			    batchIds: '',
				oldData: {},
			    ipPageType: 'isUsed',
				serverGroupIdSel: '',
			    ipTypeSel:'',
			    submitFlag: 0
			};
		    $('.bdb-header-left > span').attr('data-type', this.ipPageType).text('已上架IP');
			this.list();
		},

	  	/* 添加ip事件 */
		addEvent: function() {
			var _this = this,
				addVerifyObj;

			addVerifyObj = $('#bdb-ip-add-form').validate({
				errorElement: "div",
				errorPlacement: function(error, element) {
					error.addClass("help-block");
					if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
						error.appendTo(element.parents(".bdb-vc"));
					} else {
						error.insertAfter(element);
					}
				},
				submitHandler: function(form, e) {
					e.preventDefault();
					_this.addSubmit(form);
				}
			});

			$('#bdb-ip-add').off('click').on('click', function() {
			  	_this.ipTypeChange(addVerifyObj);
			});

			$('#bdb-ip-add-dialog, #bdb-ip-edit-dialog').find('.js-bdb-resetSubmitFlag').off('click.resetSubmitFlag').on('click.resetSubmitFlag', function() {
				_this.pageState.submitFlag = 0;
			});
		},

		/* 选择IP类型 */
		ipTypeChange: function(verifyObj, selectIpType) {
			var _this = this,
				DialogEle = $('.bdb-dialog'),
				iptype = _this.defData.ipType,
				typeHtml = bdbMain.attr.selDefOption;

			if (arguments.length == 2) {
				$.each(iptype, function(i, v) {
					if (i == selectIpType) {
						typeHtml += '<option value="' + i + '" selected>' + v + '</option>';
					} else {
						typeHtml += '<option value="' + i + '">' + v + '</option>';
					}
				});
				DialogEle.find('[name = "ipType"]').html(typeHtml);

				bdbMain.mLSleep({loading: false}, function() {
					$(".bdbBlankEle").bdbDialog({
						ele: '#bdb-ip-edit-dialog',
						formObj: verifyObj,
						form: $('#bdb-ip-edit-form'),
						verifyResetInfo: true
					});
				});
			} else {
			  	bdbMain.mLRManag({mask: true, loading: true});
				$.each(iptype, function(i, v) {
					typeHtml += '<option value="' + i + '">' + v + '</option>';
				});
			    DialogEle.find('[name = "ipType"]').html(typeHtml);

			    bdbMain.mLSleep({loading: false}, function() {
					$(".bdbBlankEle").bdbDialog({
						ele: '#bdb-ip-add-dialog',
						formObj: verifyObj,
						form: $('#bdb-ip-add-form'),
						reset: true
					});
				});
			}
		},

		/* 添加IP */
		addSubmit: function(form) {
			var _this = this,
				form = $(form);

			if (!bdbMain.ajaxInfo.state) {
				bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
				return;
			}

			bdbMain.ajaxInfo.state = 0;
		  	bdbMain.mLRManag({maskUp: 101, loading: true});
			$.post('/ServerIp/addIp', {
			  	ip: form.find('#ipAddressAdd').val(),
			    hostname: form.find('#hostnameAdd').val(),
			    ipType: form.find('#ipTypeAdd').val(),
			    serverArea: form.find('#serverAreaIDAdd').val(),
			  	flag: _this.pageState.submitFlag
			}, function(response) {
				if (response.code == 0) {
					$(".js-bdb-dialog-cancel").click();
					bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 1, msg: '添加成功.'}});
					bdbMain.mLSleep({}, function() {
					  	_this.resetPageState();
					});
				} else if (response.code == 104004) {
				  	bdbMain.mLRManag({loading: false});
					_this.hostConfirm();
				} else {
				    bdbMain.mLSleep({maskDown: 99, loading: false, alert:{type: 2, msg: response.msg}});
				}
				bdbMain.ajaxInfo.state = 1;
			});
		},

	  	/* 主机名重复确认提交按钮 */
	  	hostConfirm: function() {
			var _this = this;
			bdbMain.confirm({
				textInfo: {
					content: '已保存该主机名，是否提交？',
					btn: {}
				},
			  	closeMaskFunc: function() {
				  	bdbMain.mLRManag({maskDown: 101});
				},
				note: false,
				callback: function(ele) {
					bdbMain.mLRManag({maskDown: 101, loading: false});
					_this.pageState.submitFlag = 1;
					ele.hide();
				}
			});
		},

	  	/* 设置列表 */
	  	setEvent: function() {
			var _this = this,
				modifyVerifyObj;

		  	bdbMain.mLRManag({mask: true, loading: true});
			$.post('/ServerIp/editIpInit', {
			  	id: _this.pageState.modifiedId
			}, function(response) {
				if (response.code == 0) {

					$('#ipAddressEdit').val(response.data.ip);
					$('#hostnameEdit').val(response.data.hostname);
					$('#serverAreaIDEdit').val(response.data.server_area);
					_this.pageState.oldData = response.data;

					modifyVerifyObj = $('#bdb-ip-edit-form').validate({
						errorElement: "div",
						errorPlacement: function(error, element) {
							error.addClass("help-block");
							if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
								error.appendTo(element.parents(".bdb-vc"));
							} else {
								error.insertAfter(element);
							}
						},
						submitHandler: function(form, e) {
							e.preventDefault();
							_this.modifySubmit(form);
						}
					});

					_this.ipTypeChange(modifyVerifyObj, parseInt(response.data.ip_type));
				} else {
				    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
				}
			});
		},

	  	/* 提交设置 */
	    modifySubmit: function(form) {
		    var _this = this,
				form = $(form),
				data = _this.pageState.oldData;

			// 请求已发出.
			if (!bdbMain.ajaxInfo.state) {
				bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
				return ;
			}

			// 发送请求.
			bdbMain.ajaxInfo.state = 0; // 加锁.
		  	bdbMain.mLRManag({maskUp: 101, loading: true});
		    $.post('/ServerIp/editIp', {
				id:_this.pageState.modifiedId,
				hostname: form.find('#hostnameEdit').val(),
				serverArea: form.find('#serverAreaIDEdit').val(),
				ipType: form.find('#ipTypeEdit').val(),
				oldHostname: data.hostname,
				oldServerArea: data.server_area,
				oldIpType: data.ip_type,
				flag: _this.pageState.submitFlag
			}, function(response) {
				if (response.code == 0) {
					$(".js-bdb-dialog-cancel").click();
					bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 1, msg: '修改成功.'}});
					bdbMain.mLSleep({}, function() {
					    _this.list({page: _this.pageState.page});
					});
				} else if(response.code == 104004) {
				  	bdbMain.mLRManag({loading: false});
					_this.hostConfirm();
				} else {
					bdbMain.mLRManag({maskDown: 99, loading: false, alert:{type: 2, msg: response.msg}});
				}
			    bdbMain.ajaxInfo.state = 1; // 释放锁.
			});
		},

	  	/* 批量设置IP类型 */
	  	batchSetIPType: function() {
			var _this = this,
				ipTypeTpl = bdbMain.attr.selDefOption;

			$.each(_this.defData.ipType, function (index, value) {
				ipTypeTpl += '<option value="' + index + '">' + value + '</option>';
			});
		    $('#bdb-ipType-tpl-dialog #templateId').html(ipTypeTpl);
		    _this.batchSetIPTypeVery();
		},

	  	/* 批量设置ip类型验证 */
		batchSetIPTypeVery: function() {
			var _this = this,
				formVerify;

			// 验证.
			formVerify = $('#bdb-ipType-tpl-form').validate({
				errorElement: "div",
				errorPlacement: function(error, element) {
					error.addClass("help-block");
					if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
						error.appendTo(element.parents(".bdb-vc"));
					} else {
						error.insertAfter(element);
					}
				},
				submitHandler: function(form, e) {
					e.preventDefault();
					_this.batchSetIPTypeSave(form);
				}
			});

			// dialog.
			$('.bdbBlankEle').bdbDialog({
				ele: '#bdb-ipType-tpl-dialog',
				formObj: formVerify,
				form: $('#bdb-ipType-tpl-form'),
				reset: true
			});
		},

	    /* 批量设置ip类型保存 */
		batchSetIPTypeSave: function(form) {
			var _this = this,
				form = $(form);

			// 请求已发出.
			if (!bdbMain.ajaxInfo.state) {
				bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
				return ;
			}

			// 发送请求.
			bdbMain.ajaxInfo.state = 0; // 加锁.
			bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
			$.post('/ServerIp/batchSetIpType', {
				id: _this.pageState.batchIds,
				ipType: form.find("#templateId").val()
			}, function(response) {
				if (response.code == 0) {
					$(".js-bdb-dialog-cancel").click();
					bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 1, msg: '修改成功'}});
				    _this.list({page: _this.pageState.page});
				} else {
					bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 2, msg: response.msg}});
				}
				bdbMain.ajaxInfo.state = 1; // 释放锁.
			});
		  },

	  	/* 暂停/启动 */
		startupPauseEvent: function(dataID, dataStatus) {
			var _this = this,
				optCont = dataStatus == 1 ? '暂停' : '启用';
				dataStatus == 1 ? dataStatus = 0 : dataStatus == 0 ? dataStatus = 1 : null;

			bdbMain.confirm({
				textInfo: {
					content: '确定要' + optCont + '吗？',
					btn: {
						ok: optCont,
						cancel: '取消'
					}
				},
				note: true,
				callback: function(ele) {
					_this.startupPauseProc(ele, dataID, dataStatus);
				}
			});
		},

	    /* 暂停/启用接口 */
	  	startupPauseProc: function(ele, dataID, dataStatus) {
			var _this = this;

			bdbMain.mLRManag({mask: true, loading: true});
			$.post('/ServerIp/pauseIp', {
				id:dataID,
				status:dataStatus,
				comment:ele.find('#bdb-confirm-note').val()
			}, function (res) {
			  	ele.hide();
				if (res.code == 0) {
				  	bdbMain.mLSleep({loading: false}, function() {
					  	_this.list({page: _this.pageState.page});
					});
				} else {
					bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 2, msg: res.msg}});
				}
			});
		},

		/* 列表操作按钮 */
		listEvent: function() {
			var _this = this;
			$('.bdb-list').off('click').on('click', '.bdb-option-btn', function(e) {
			  	e.stopPropagation();
				var ele = $(e.target),
					dataID = ele.parents('.bdb-list-row').attr('data-id'),
					dataStatus = ele.parents('.bdb-list-row').attr('data-status');

				if (ele.hasClass('ip-opt-set')) {
				  	_this.pageState.modifiedId = dataID;
					_this.setEvent();
				} else if (ele.hasClass('ip-start-pause')) {
					_this.startupPauseEvent(dataID, dataStatus);
				}
			});
		},

		/* 批量操作按钮 */
		batchListEvent: function() {
			var _this = this;
			$('.batch-option').off('click').on('click', '.lot', function(e) {
				var eleId = $(e.target).attr('id'),
					dataID = '',
					isSame = [];

				/* 获取选中的元素 */
				if ($('.bdb-list .check-icon.checkYes').length <= 0) {
					bdbMain.mLRManag({alert: {type: 2, msg: '请选择要操作的记录行!'}});
					return ;
				}

				var tempArr = [],
					everySame = true;

				$(".bdb-list-row .checkYes").each(function(i, n) {
					tempArr.push($(n).parent().attr('data-id'));
					dataID = tempArr.join(',');
					isSame.push($(n).parent().attr('data-status'));
				});

			    _this.pageState.batchIds = dataID;
				/* 点击对应的批量操作按钮 */
				if (eleId == 'start') {
					everySame = isSame.every(function(v) {
						return v == 1;
					});

					if (everySame) {
						bdbMain.mLRManag({alert: {type: 2, msg: '记录都已处于开启状态!'}});
					} else {
						_this.startupPauseEvent(dataID, 0);
					}
				} else if (eleId == 'pause') {
					everySame = isSame.every(function(v) {
						return v == 0;
					});

					if (everySame) {
						bdbMain.mLRManag({alert: {type: 2, msg: '记录都已处于暂停状态!'}});
					} else {
						_this.startupPauseEvent(dataID, 1);
					}
				} else {
					_this.batchSetIPType();
				}
			});
		},

	    /* 列表展示 */
	  	list: function(obj) {
			var _this = this,
				obj = obj || {page: 1};

		    _this.pageState.page = obj.page;
		    bdbMain.mLRManag({mask: true, loading: true});

		    $('.bdb-table-header .check-all-icon').removeClass('checkAll').addClass('checkNone'); //重置选择按钮
			$.post('/ServerIp/ipList', {
				pageNumber : _this.pageState.page,
				pageSize : _this.defData.pageSize,
				type: _this.pageState.ipPageType,
				serverGroupId : _this.pageState.serverGroupIdSel,
			  	ipType : _this.pageState.ipTypeSel,
				query: _this.pageState.search,
			  	listSize: _this.defData.listSize
			}, function(response) {
				if (response.code == 0) {
					var listHtml =_this.listProc(response.data.list),
						totalRowCont = response.data.totalCount;

				  	_this.defData.ipType = response.data.ipType;
					$('.bdb-list').html(listHtml);
					_this.listNull(totalRowCont); // 搜索或列表无数据时的展示

					// 加载分页
					$('#js-bdb-creatPage').bdbPagination({
						totalRowCnt : totalRowCont,
						currentPage : _this.pageState.page,
						pageSize : _this.defData.pageSize
					});

				    // 数据总条数展示
					$('.bdb-record-cnt').html(bdbMain.pageInfo.recordCnt.replace('{cnt}',totalRowCont));
					_this.defData.serverGroupId = response.data.serverGroup;

					// 鼠标滑过显示三条日志
					$('.js-show-tip').bdbTip({
					  	eleTopMargin: 129,
					  	eleBottomMargin: 53,
						space: 0,
						minWidth: 380,
						maxWidth: 380,
						padding: '0px 30px 15px 30px',
						params: ['time', 'real_name', 'operate_type', 'detail'],
						tpl: '<div class="title-row clearfix"><div class="col-md-6 bdb-text-align-l">{data.time}</div><span class="tip-split-line"></span><div class="col-md-2">{data.real_name}' + ':' + '</div><div class="col-md-4 bdb-text-align-l">{data.operate_type}</div></div><div class="discripe-row clearfix"><div class="col-md-12 bdb-text-align-l bdb-tip-break-word">{data.detail}</div></div>'
					});

				 	 bdbMain.mLSleep({mask: false, loading: false});
				} else {
				     bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
				}
			});
		},

	  	/* 列表模板 */
	  	listProc: function(data) {
			var _this = this,
				tplHtml = '';

			$.each(data, function(index, value) {
				var imgSrc = '',
					optText = '',
					ipLog = '',
					ipType = value.ip_type ? value.ip_type : '';

				if (value.status == 1) {
					imgSrc = "point-green.svg";
					optText = '暂停';
				}  else {
					imgSrc = "point-gray.svg";
					optText = '启用';
				}

			  	ipLog = JSON.stringify(value.ip_log);

				tplHtml += "<div class='bdb-list-row' data-id='" + value.ip_id + "' data-status='" + value.status + "'>\
								<div class='bdb-mx-w-col1 check-icon checkNo'></div>\
								<div class='bdb-mx-w-col2'><img src='/static/imgs/global/" + imgSrc + "'></div>\
								<div class='bdb-mx-w-col3 bdb-ellipsis'>" + value.ip + "</div>\
								<div class='bdb-mx-w-col4 bdb-ellipsis'>" + value.hostname + "</div>\
								<div class='bdb-mx-w-col5 bdb-ellipsis'>" + value.server_area + "</div>\
								<div class='bdb-mx-w-col6 bdb-ellipsis'>" + value.server_name + "</div>\
								<div class='bdb-mx-w-col7 bdb-ellipsis'>" + ipType + "</div>\
								<div class='bdb-mx-w-col8 bdb-p-r'><div class='js-show-tip bdb-ellipsis bdb-text-align-c'  data-title='" + ipLog + "'>" + value.real_name + "</div></div>\
								<div class='bdb-mx-w-col9 bdb-ellipsis'>" + value.update_time + "</div>\
								<div class='bdb-mx-w-col10'>\
									<div class='bdb-option-btn bdb-p-r bdb-mgn-t-10'>\
										<a class='bdb-mgn-l--1 ip-opt-set' href='javascript:void(0);'>设置</a>\
										<div class='v-line-ffa007'></div>\
										<a class='bdb-mgn-l--1 ip-start-pause' href='javascript:void(0);'>" + optText + "</a>\
										<div class='v-line-ffa007'></div>\
										<a class='bdb-mgn-l--1 ip-opt-log' href='ipLogList/" + value.ip_id + "'>日志</a>\
									</div>\
								</div>\
							 </div>";
			});

		  	return tplHtml;
		},

		/* 暂无数据展示 */
		listNull: function(totalRowCnt) {
			var noResult = $('.bdb-no-result'),
				noSearchRecord = $('.bdb-no-search-record');

			if (totalRowCnt <= 0) {
				if (this.pageState.noData == 'search') { // 查询无结果
					noResult.hide();
					noSearchRecord.show();
				} else { // 暂无记录.
					noResult.show();
					noSearchRecord.hide();
				}
			} else {
				noResult.hide();
				noSearchRecord.hide();
			}
		},

	  	/* 分页事件 */
	  	pageEvent: function () {
		  	var _this = this;

			$('.bdb-creatPage').off('click').on('click', '.bdb-pagination', function(e) {
				e.preventDefault();
				var page = parseInt($(e.target).text());
				if (!isNaN(page)) {
					_this.list({page: page});
				}
			})

		},

	  	/* 搜索事件 */
		searchEvent: function() {
			var _this = this,
				searchInputEle = $('.bdb-search-input');

			searchInputEle.off('focusin').on('focusin', '.search-text', function(e) {
				var _cThis = $(this),
					_btnEle = $(this).parent().find('span');

				if (!_btnEle.hasClass('search-clear')) {
				    _cThis.animate({width: '240px'}, 500);
					_btnEle.animate({ left : '240px' }, 500, function() {
						_btnEle.removeClass('search-gray').addClass('search-blue');
					});
				}
			});

			searchInputEle.off('click').on('click', 'span', function(e) {
			    var left = parseInt($(this).css('left'));
				if ($(this).hasClass('search-blue') && left > 0) {
					_this.pageState.search = searchInputEle.find('.search-text').val();
					_this.pageState.noData = 'search';
				    $(this).removeClass('search-blue').addClass('search-clear');
					_this.list();
				} else if (left > 0) {
					searchInputEle.find('.search-text').val('');
					_this.pageState.search = '';
					_this.pageState.noData = 'def';
					$(this).removeClass('search-clear').addClass('search-blue');
					_this.list();
				}
			});
		},

	  	/* ip类型菜单选择 */
	  	ipMenuSelect: function() {
		  	var _this = this,
				eleP = $('.ipMenuItems');

			$('.bdb-header-left').off('mouseenter').on('mouseenter', function(e) {
			  	e.stopPropagation();
			  	eleP.fadeIn();
			}).off('mouseleave').on('mouseleave', function(e) {
				e.stopPropagation();
				eleP.hide();
			});

			eleP.off('click').on('click', 'li', function(e) {
				e.stopPropagation();
				var eleSpan = $(this).parents('.bdb-header-left').find('span'),
					ele = $(e.target);

				eleSpan.text(ele.text());
				eleSpan.attr('data-type', ele.attr('data-type'));
				_this.pageState.ipPageType = ele.attr('data-type');
				_this.pageState.search = '';
				_this.pageState.serverGroupIdSel = '';
			  	eleP.hide();
				_this.list();
			});
		},

	    /* 服务器组分类 */
	    serverGroupSort: function() {
			var _this = this,
				ele = $('#bdb-ip-server-group-list');

			ele.off('click').on('click', 'li', function(e) {
				e.stopPropagation();
				_this.pageState.serverGroupIdSel = $(this).attr('data-id');
			  	ele.hide();
				_this.list();
			});

			$('#bdb-ip-server-group').off('click').on('click', function(e) {
			  	e.stopPropagation();
				$(this).find('span').css('background-color', '#fafafa');
				if (ele.find('li').length <= 0) {
					_this.serverGroupSelProc($(this));
				} else {
					ele.fadeIn();
				}
			}).off('mouselevae').on('mouseleave', function() {
				ele.hide();
				$(this).find('span').css('background-color', '#fff');
			});

		},

	    /* 服务器组分类模板 */
	    serverGroupSelProc: function(ele) {
			var _this = this,
				ele = ele.find('#bdb-ip-server-group-list');

			var pTHtml = '';
				pTHtml += '<li class="server-group-search">\
						  <img class="search_logo" src="/static/imgs/global/search-white.svg">\
						  <input type="text" id="searchContent" placeholder="Search">\
						  <li class="js-search-item" data-id="">全部</li>\
						  </li>';

			$.each(_this.defData.serverGroupId, function(i, n) {
				pTHtml += '<li class="js-search-item bdb-ellipsis" data-id="' + i + '">' + n + '</li>';
			});

			pTHtml += '<li class="bd-hide js-serversSearchNull" style="display:none;">没有搜索到匹配的结果</li>';
			$('#bdb-ip-server-group-list').html(pTHtml);

			// 显示.
			ele.show();
			_this.serverGroupSearch();
		},

	    /* 服务器组分类搜索 */
	  	serverGroupSearch: function() {
		  	var _this = this;
		  	$('#searchContent').off('click').on('click', function(e) {
			  	e.stopPropagation();
			});

			$('#searchContent').off('keyup').on('keyup', function(e) {
				var that = this,
					val = $(that).val(),
					searchItem = $('.js-search-item');

			    searchItem.each(function(i, n){
				var that = $(n),
					eleText = that.text();

					if(eleText.indexOf(val) == -1){
						that.hide();
					}else{
						that.show();
					}
				});

				var domainSearchNull = $(".js-serversSearchNull");
				if($(".js-search-item:visible").length){
					domainSearchNull.hide();
				}else{
					domainSearchNull.show();
				}
			});
		},

	  	/* ip类型分类 */
	  	ipTypeSort:function () {
			var _this = this,
				ele = $('#bdb-ip-type-list');

			ele.off('click').on('click', 'li', function(e) {
				e.stopPropagation();
				_this.pageState.ipTypeSel = $(this).attr('data-id');
				ele.hide();
				_this.list();
			});

			$('#bdb-ip-type').off('click').on('click', function(e) {
				e.stopPropagation();
				$(this).find('span').css('background-color', '#fafafa');
				if (ele.find('li').length <= 0) {
				  _this.ipTypeSortPro($(this));
				} else {
					ele.fadeIn();
				}
			}).off('mouselevae').on('mouseleave', function() {
				ele.hide();
				$(this).find('span').css('background-color', '#fff');
			});
		},

	  	/* ip类型分类模板 */
	  	ipTypeSortPro: function (element) {
			var _this = this,
				ele = element.find('#bdb-ip-type-list');

			var pTHtml = '';
		  	pTHtml += '<li>全部</li>';
			$.each(_this.defData.ipType, function(i, n) {
			  pTHtml += '<li class="js-search-item bdb-ellipsis" data-id="' + i + '">' + n + '</li>';
			});
			ele.html(pTHtml);
			// 显示.
			ele.show();
		},

	  	/* 自适应屏幕宽度 */
		contentSizeResize: function() {
			$(window).resize(function() {
				$('.bdb-list').bdbScreenH(1);
			});
		},

  	  	init: function() {
			var _this = this;

			_this.list();
			_this.ipMenuSelect();
			_this.pageEvent();
			_this.listEvent();
			_this.serverGroupSort();
			_this.ipTypeSort();
		    _this.searchEvent();
		    _this.batchListEvent();
			_this.addEvent();
			_this.contentSizeResize();

			$('.bdb-container').bdbCheckBox();
			$('.bdb-list').bdbScreenH(1);
		}
	};
  	bdbIpManage.init();
});